package com.hanson.api;

import com.hanson.common.bean.ResultMessage;
import com.hanson.service.GoodsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags = "商品类型管理")
@RestController
@RequestMapping("/api/goodsType")
public class GoodsTypeApiController {
    @Autowired
    private GoodsTypeService goodsTypeService;

    @ApiOperation(value = "根据类型查询一级分类", notes = "type 1:用途 2:材质")
    @RequestMapping(value = "/getRootGoodsType/{type}", method = RequestMethod.GET)
    public ResultMessage getRootGoodsType(@PathVariable Integer type) throws Exception {
        return ResultMessage.success(goodsTypeService.selecPidAndType(0, type), null);
    }

    @ApiOperation(value = "根据一级分类查询二级分类")
    @RequestMapping(value = "/getChildGoodsType/{pid}", method = RequestMethod.GET)
    public ResultMessage getChildGoodsType(@PathVariable Integer pid) throws Exception {
        return ResultMessage.success(goodsTypeService.selectByPid(pid), null);
    }


}
